Skip to content

Remove DerefMut impl for JS::MutableHandle#574

Merged
sagudev merged 2 commits intoservo:mainfrom
gmorenz:js_mutable_handle_deref_mut
Mar 26, 2025
Merged

Remove DerefMut impl for JS::MutableHandle#574
sagudev merged 2 commits intoservo:mainfrom
gmorenz:js_mutable_handle_deref_mut

Conversation

@gmorenz
Copy link
Copy Markdown
Contributor

@gmorenz gmorenz commented Mar 26, 2025

Like with #572 and #573 this impl allows for improper aliasing with the GC. With this type it also allows for outright use after frees, since JS::MutableHandle, like a raw pointer, has no lifetime attached to it. Eventually that's a justification for removing the Deref impl as well, but once thing at a time.

There's only one use of this in servo, which is removed in the accompanying PR: servo/servo#36161

Like with #572 and #573 I added an unsafe as_mut method, though it is unused locally this time as well as in servo. It feels like a reasonable escape hatch to share even if it isn't currently used.

Part of #569, and can be merged entirely independently from #572 and #573.

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>
Comment thread mozjs-sys/src/jsimpls.rs Outdated
Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>
@gmorenz gmorenz force-pushed the js_mutable_handle_deref_mut branch from 727956e to 1658f77 Compare March 26, 2025 15:13
Comment thread mozjs-sys/src/jsimpls.rs
unsafe { *self.ptr = v }
}

/// The returned pointer is aliased by a pointer that the GC will read
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a task to the tracking issue to update this comment if we don't convert the GC to only write via interior mutability.

@sagudev sagudev added this pull request to the merge queue Mar 26, 2025
Merged via the queue into servo:main with commit db131fc Mar 26, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants